/**
 * @file tkl_zcl_ota.h
 * @brief Common process - ota inner
 * @version 1.0.0
 * @date 2021-04-21
 *
 * @copyright Copyright 2021-2022 Tuya Inc. All Rights Reserved.
 *
 */

#ifndef __TKL_ZCL_OTA_H__
#define __TKL_ZCL_OTA_H__

#ifdef __cplusplus
	extern "C" {
#endif

#include "tuya_cloud_types.h"

/*
 * zigbee ota end result micro
 */
#define ZG_OTA_DOWNLOAD_AND_VERIFY_SUCCESS 0 ///< OTA successful
#define ZG_OTA_DOWNLOAD_TIME_OUT           1 ///< OTA timeout
#define ZG_OTA_VERIFY_FAILED               2 ///< OTA image validation failed
#define ZG_OTA_SERVER_ABORTED              3 ///< An OTA server side exception
#define ZG_OTA_CLIENT_ABORTED              4 ///< An OTA client side exception
#define ZG_OTA_ERASE_FAILED                5 ///< Erase flash exceptions


typedef VOID_T (*TKL_ZG_OTA_START_CB)(UINT32_T image_size, VOID_T* argv);

typedef VOID_T (*TKL_ZG_OTA_END_CB)(UINT8_T result);

/*
 * zigbee ota callback collection
 */
typedef struct {
    // zigbee ota start callback
    TKL_ZG_OTA_START_CB start_notify;
    // zigbee ota end callback
    TKL_ZG_OTA_END_CB end_notify;
} TKL_ZG_OTA_CB;

/**
 * @brief zigbee differential OTA disable(default enable)
 * 
 * @param[in]   is_enable: TRUE: disable; FALSE: enable
 * @return none
 */
VOID_T tkl_zg_diff_ota_disable(BOOL_T is_enable);

/**
 * @brief zigbee ota callback register
 * 
 * @param[in]   ota_cb: pointer to ota callback
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tkl_zg_register_ota_cb(TKL_ZG_OTA_CB *ota_cb);



/**
* @brief ota init
 * this API will insert to native SDK
 * 
 * @param[in] app_ver:  app current version
 * @param[in] manuf_id:  manufacturer id
 * @param[in] image_type:  ota image type
 *
 * @note This API is used for ota init
 *
 * @return none
 */
VOID_T tkl_ota_init(UINT_T app_ver, UINT16_T manuf_id, UINT16_T image_type);


/**
* @brief ota auto query enable
 * this API will insert to native SDK
 * 
 * @param[in] enable:  switch on/off OTA-query
 *
 * @note This API is used for ota policy
 *
 * @return none
 */
VOID_T tkl_ota_auto_query_enable(BOOL_T enable);

#ifdef __cplusplus
}
#endif
#endif
